﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bitirme.Controllers;

namespace Bitirme.Views
{
    public partial class AddProject : System.Web.UI.Page 
    {
        private void FillData()
        {
            ProjectManagerHandler managerHandler = new ProjectManagerHandler();

            PMDropDownList.DataSource = managerHandler.GetAllProjectManagers();
            PMDropDownList.DataTextField = "Name";
            PMDropDownList.DataValueField = "ID";
            PMDropDownList.DataBind();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            FillData();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            ProjectHandler projectHandler = new ProjectHandler();
            string Name = NameTextBox.Text;
            string Subject = SubjectTextBox.Text;
            string Details = DetailsTextBox.Text;
            int Duration = Convert.ToInt32(DurationTextBox.Text);
            int ProjectState = Convert.ToInt32(ProjectStateList.SelectedItem.Value);
            decimal Cost = Convert.ToDecimal(CostTextBox.Text);
            int ProjectManagerID = Convert.ToInt32(PMDropDownList.SelectedItem.Value);
            string StartDate = startdate.Text;
            string EndDate = enddate.Text;

            int intResult;
            try
            {

                intResult = projectHandler.InsertProject(Name, Subject, Details, ProjectState, Duration, Cost, ProjectManagerID, StartDate, EndDate);

                if (intResult > 0)

                    lblMessage.Text = "Proje başarıyla eklendi. :" + intResult;

                else

                    lblMessage.Text = "Hata: Proje yaratılamadı!";



            }

            catch (Exception ee)
            {

                lblMessage.Text = ee.Message.ToString();

            }

            finally
            {

                projectHandler = null;

            }        


        }

    }
}